<?php
class NeighborsPlugin {
    var $ld;
	var $xmlsOb;
    var $bot;
    var $np;

    // ==========================================================================
    function NeighborsPlugin()
    {
        $this->ld = new LocalData();
	    $this->xmlsOb = new xmlsOb();
        $this->bot = new Bot();
        //$np = new NeighborsPlugin();

    }
    // ==========================================================================
    function GetOptionsByClassName($name)
    {
        $res="<option>any</option>";
        foreach ($this->xmlsOb->gsXML->items->item as $item) {
            if ((string)$item['className'] == $name){
                $res=$res."<option>".(string)$item['name']."</option>";
            }
        }
        return $res;
    }
    // ==========================================================================
    function GetOptionsByTypeName($name)
    {
        $arr = "";
        $res="<option>any</option>";
        foreach ($this->xmlsOb->gsXML->items->item as $item)
        {
          if ((string)$item['type'] == $name) $arr[] = (string)$item['name'];
        }
        natcasesort($arr);
        foreach ($arr as $item)
        {
          $res=$res."<option>".$item."</option>";
        }
        return $res;
    }

 	// ==========================================================================
	function GetOptionByTypeAndKeyword($name, $keyword)
	{  
		global $imagePath;
		$res="<option>any</option>";
		foreach ($this->xmlsOb->gsXML->items->item as $item) {
			if ((string)$item['type'] == $name)
			{
				if((string)$item->keyword [1] == $keyword)
				$res=$res."<option>".(string)$item['name']."</option>";
			}
		}
		return $res;
	}	
	// ==========================================================================
    function GetALLFranchise()
    {
        $arr = "";
        //$res="<option>any</option>";
        foreach ($this->xmlsOb->gsXML->items->item as $item)
        {
          //if ( ((string)$item['type'] == "residence") ||
          //     ((string)$item['type'] == "business") ||
          //     ((string)$item['type'] == "landmark") ||
          //     ((string)$item['type'] == "municipal") ||
          //     ((string)$item['type'] == "decoration")
          //   )
          if ((string)$item['placeable'] == "true") $arr[] = (string)$item['name'];
        }
        natcasesort($arr);
        foreach ($arr as $item)
        {
          $res=$res."<option>".$item."</option>";
        }
        return $res;
    }
    // ==========================================================================
    function NlistCheck() {
        $is = false;
        $res = ($this->ld->GetSelect('SELECT count(*) as cnt FROM sqlite_master where tbl_name="neighbors"'));

        if ($res[0]["cnt"]==1) {
            $is = true;
        }
        return $is;
    }
    // ==========================================================================
   /* function GetNList() {
        $res = "";
        $sel = ($this->ld->GetSelect('SELECT count(*) as cnt FROM sqlite_master where tbl_name="neighbors"'));
        if ($sel[0]["cnt"] > 1) {
            $sel = ($this->ld->GetSelect('SELECT count(*) as cnt FROM neighbors'));
            if ($sel[0]["cnt"] > 0) {
                $sel = ($this->ld->GetSelect('SELECT value FROM neighbors'));
                foreach ($sel as $n){
                    $tmp=array();
                    $tmp=unserialize(base64_decode($n['value']));
                    //$tmp=unserialize($n['value']);
                    $res[]= array( 'uid'=>$tmp['uid'], 'cityname'=>$tmp['cityname'] ) ; //unserialize($n['value']);
                    //$res[]= array( 'uid'=>$n['value'], 'worldName'=>$n['value'] ) ; //unserialize($n['value']);
                }
            }
        }
        return $res;
    }*/
    function GetNList() {
        $res = "";
        $sel = ($this->ld->GetSelect('SELECT count(*) as cnt FROM neighborlist'));
        if ($sel[0]["cnt"] > 0)
        {
          $sel = ($this->ld->GetSelect('SELECT * FROM neighborlist order by level'));
          foreach ($sel as $n)
          {
            //0[uid] NVARCHAR(25) NULL,
            //1[name] NVARCHAR(50) NULL,
            //2[picture] NVARCHAR(50) NULL,
            //3[cityname] NVARCHAR(50) NULL,
            //4[xp] NVARCHAR(10) NULL,
            //5[coins] NVARCHAR(20) NULL,
            //6[level] NVARCHAR(5)  NULL)

            //$tmp=unserialize($n['value']);
            $aa = "$n[3] ($n[1])";

            $aa = str_replace ( "'", " ", $aa);
            $res[]= array( 'uid'=>$n[0], 'cityname'=>$aa) ; //unserialize($n['value']);
            //$res[]= array( 'uid'=>$n['value'], 'worldName'=>$n['value'] ) ; //unserialize($n['value']);
          }
        }
        return $res;
    }
    // ==========================================================================
    function GetFList() {
        $res = "";
        $sel = ($this->ld->GetSelect('SELECT count(*) as cnt FROM fpending'));
        if ($sel[0]["cnt"] > 0)
        {
          $sel = ($this->ld->GetSelect('SELECT * FROM fpending order by lotId'));
          foreach ($sel as $n)
          {
            //0[lotId] NVARCHAR(6) NULL,
            //1[resourceType] NVARCHAR(50) NULL,
            //2[senderID] NVARCHAR(15) NULL

            //$tmp=unserialize($n['value']);
            $aa = "$n[0] ($n[1]-$n[2])";

            $aa = str_replace ( "'", " ", $aa);
            $res[]= array( 'lid'=>$n[0], 'lotsite'=>$aa, 'senderID'=>$n[2]) ; //unserialize($n['value']);
            //$res[]= array( 'uid'=>$n['value'], 'worldName'=>$n['value'] ) ; //unserialize($n['value']);
          }
        }
        return $res;
    }
    // ==========================================================================
    function GetForm($server)
    {
      $PlVersion = (array)$this->ld->GetPlVersion('neighborsplugin');
      echo '
      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
     <html xmlns="http://www.w3.org/1999/xhtml" lang="ru">
     <head>
        <title>Neighbors helper</title>
        <script src="..\..\codebase-php\jquery-1.4.2.min.js"></script>
        <script src="..\..\codebase-php\jquery.json-2.2.min.js"></script>
        <link href="helpers\menu.css" rel="stylesheet" type="text/css">
        <script type="text/javascript" src="helpers/menu.js"></script>
        <style>
            body{ font-family: Verdana, Arial, Helvetica, sans-serif; background-color: rgb(255, 249, 200); font-size: 10pt; margin: 24px 0; padding: 0;}
            .zag{ font-size: 15pt; font-weight: bold; }
            .zag2{ font-size: 13pt; font-weight: bold; width: 300px; }
            h1 { color: #0B0B3B; font-size: 15pt; margin: 0 0 5px 10px; white-space: nowrap; font-weight: bold; }
            h2 { color: #0B0B3B; font-size: 12pt; margin: 0 0 0 10px; white-space: nowrap; font-weight: bold; }
            h3 { color: #ffffff; font-size: 12pt; margin: 0 0 0 10px; white-space: nowrap; font-weight: bold; }

            #nsp { width: 150px; }
            #maint{  font-size: 10pt;    width: 850px;     padding: 0px;     }
            #rcontent{  padding-left: 20px;   }
            #treesIN, #treesIN2, #cropsIN, #animalIN, #debrisIN{        width: 200px;      }

            #menuwrapper, #p7menubar ul a {height: 1%;}
            a:active {width: auto;}
        </style>
        <hta:application
        id="oHTA"
        icon="http://www.microsoft.com/windows/Framework/images/favicon.ico"
        innerBorder="no"
        scroll="no"
        />
     <script>
     //======================================================================
     function changeText()
     {
       var boldtext = "<font style=\'font-weight:bold;font-size:13px;\'>"
       for(var key in window.nlist)
       {
         if(window.nlist[key]["uid"]==$("#nsp option:selected").attr("id"))
         {
           var nbobj=window.nlist[key];
         }
       }

       if(nbobj!==undefined)
       {
         var newDate = new Date();
         newDate.setTime(nbobj["lastplayed"]*1000);

         var sdiv="";
         sdiv="<br><br>"
         sdiv=sdiv+ "Name: &nbsp;&nbsp;" +boldtext+  nbobj["worldName"]+ "&nbsp( " + nbobj["uid"] + " )&nbsp </font><br>";

         $("#rcontent").html(sdiv);
       }
     }
     function WriteFile(_file,_text)
     {
       var fso  = new ActiveXObject("Scripting.FileSystemObject");
       var fh = fso.CreateTextFile(_file, true);
       fh.WriteLine(_text);
       fh.Close();
     }
     //======================================================================
     $(document).ready(function()
     {
       window.nlist=eval(' . json_encode($this->GetNList()) . ');
       window.flist=eval(' . json_encode($this->GetFList()) . ');
       window.settings=eval(' . json_encode($this->ld->GetPlSettings('neighborsplugin')) . ');
       window.lotsite=eval(' . json_encode($this->ld->GetPlSettings('neighborspluginLotsite')) . ');
       //==============================================================
       if ((window.lotsite!==null) && (window.lotsite!==undefined))
       {
         for(var key in window.lotsite)
         {
          $("#lotsite").append("&nbsp;"+window.lotsite[key]["uid"]+"&nbsp;"+window.lotsite[key]["worldName"]+"&nbsp;"+window.lotsite[key]["itemName"]+"&nbsp;<br>");
         }
       }
       //==============================================================
       if ((window.nlist!==null) && (window.nlist!==undefined))
       {
         for(var key in window.nlist)
         {
           $("#nsp").append("<option id=\""+window.nlist[key]["uid"]+"\">"+window.nlist[key]["cityname"]+"</option>");
         }
         $("#ncount").text($("#nsp").children().length);
         $("#act_count").text($("#nsp").children().length*5);
       }
       //==============================================================
       if ((window.flist!==null) && (window.flist!==undefined))
       {
         for(var key in window.flist)
         {
           $("#asp").append("<option id=\""+window.flist[key]["lid"]+"\" id2=\""+window.flist[key]["senderID"]+"\">"+window.flist[key]["lotsite"]+"</option>");
         }
       }
       //==============================================================
       if ((window.settings!==null) && (window.settings!==undefined))
       {
         //loading edits
         $(":text").each(function ()
         {
           var attr=$(this).attr("id");
           if (window.settings[attr]!==null)
           {
            $(this).val(window.settings[attr]);
           }
           else
           {
            $(this).val("0");
           }
         });

         $("#municipalIN").val(window.settings.municipalIN);
         $("#landmarkIN").val(window.settings.landmarkIN);
         $("#residenceIN").val(window.settings.residenceIN);
         $("#businessIN").val(window.settings.businessIN);
         $("#cropsWIN").val(window.settings.cropsWIN);
         $("#cropsHIN").val(window.settings.cropsHIN);
         $("#cropsRIN").val(window.settings.cropsRIN);

         $("#shipsWIN").val(window.settings.shipsWIN);
         $("#shipsHIN").val(window.settings.shipsHIN);
         $("#shipsRIN").val(window.settings.shipsRIN);

		 $("#airWIN").val(window.settings.airWIN);
         $("#airHIN").val(window.settings.airHIN);
         $("#airRIN").val(window.settings.airRIN);
		 
		 		 
         $("#constrIN").val(window.settings.constrIN);
         $("#franchiseIN").val(window.settings.franchiseIN);
         $("#shipsIN").val(window.settings.shipsIN);
         $("#treesIN").val(window.settings.treesIN);

         //loading checkboxes
         $(":checkbox").each(function ()
         {
           if (window.settings[$(this).attr("id")] == true)
           {
             $(this).attr("checked", true);
           } else {
             $(this).attr("checked", false);
           }
         });
         //setting pause
         if ((window.settings.pause!==null) && (window.settings.pause!==undefined))
         {
           if(window.settings["pause"]==1)
           {
             $("#pause").attr("checked", true);
           }
         }
       }
       //==============================================================
       $("#btn_save").click(function()
       {

         var req=new Object();
         req.nlist=new Array();
         req.flist=new Array();

         //saving neighbor list for visiging
         chk=$("#all").attr("checked");
         if ((chk!==null) && (chk!==undefined) &&(chk==true))
         {
           req["all"]=1;
         }
         else
         {
           req["all"]=0;
           $("#nsp option:selected").each(function()
           {
             req.nlist.push($(this).attr("id")+"|"+$(this).val());
           });
         }
         //saving neighbor list for accepting franchise
         $("#asp option:selected").each(function()
         {
           req.flist.push($(this).attr("id")+"|"+$(this).val()+"|"+$(this).attr("id2"));
         });

         //saving checkboxed
         //$("input:checkbox").each(function()
         //{
         //  var par=$(this).attr("id");
         //      chk=$(this).attr("checked");
         //  if ((chk==null)||(chk==undefined))
         //  { req[par]=0; }
         //  else
         //  { req[par]=1; }
         //});
         //saving edits
         $("input:text").each(function()
         {
           req[$(this).attr("id")]=$(this).val();
         });
         if($("#AcceptN").attr("checked")==false)
         {  req["AcceptN"]=0; }
         else
         {  req["AcceptN"]=1; }
         if($("#heartP").attr("checked")==false)
         {  req["heartP"]=0; }
         else
         {  req["heartP"]=1; }
         if($("#sbVisiting").attr("checked")==false)
         {  req["sbVisiting"]=0; }
         else
         {  req["sbVisiting"]=1; }
         if($("#sbAccepting").attr("checked")==false)
         {  req["sbAccepting"]=0; }
         else
         {  req["sbAccepting"]=1; }

         if($("#pause").attr("checked")==false)
         { req["pause"]=0; }
         else
         { req["pause"]=1; }

         req["municipalIN"]=$("#municipalIN").val()[0];
         req["landmarkIN"]=$("#landmarkIN").val()[0];
         req["residenceIN"]=$("#residenceIN").val()[0];
         req["mallIN"]=$("#mallIN").val()[0];
         req["mall2IN"]=$("#mall2IN").val()[0];
         req["attractionIN"]=$("#attractionIN").val()[0];
         req["businessIN"]=$("#businessIN").val()[0];
         req["cropsWIN"]=$("#cropsWIN").val()[0];
         req["cropsHIN"]=$("#cropsHIN").val()[0];
         req["cropsRIN"]=$("#cropsRIN").val()[0];

         req["shipsWIN"]=$("#shipsWIN").val()[0];
         req["shipsHIN"]=$("#shipsHIN").val()[0];
         req["shipsRIN"]=$("#shipsRIN").val()[0];

		 req["airWIN"]=$("#airWIN").val()[0];
         req["airHIN"]=$("#airHIN").val()[0];
         req["airRIN"]=$("#airRIN").val()[0];
		 		 
         req["constrIN"]=$("#constrIN").val()[0];
         req["treesIN"]=$("#treesIN").val()[0];
         req["franchiseIN"]=$("#franchiseIN").val()[0];

         data=$.toJSON(req);
         var l=window.location.toString();
         var indx=l.indexOf(\'?\');
         var nurl=l.slice(0, indx)+"?action=save&tmp="+Math.random();
         //alert(data);
         $.post(nurl, data);
         document.location=l.slice(0, indx)+"?action=menu&click=actions1";
         return false;
       });
     });
       //======================================================================
        </script>
    </head>
    <body>';
echo '
     <h1>Original author: 12Christiaan</h1>
     <h1>Updated (11.10.2011) by Tonycell</h1>
     <br>
     <div id="menuwrapper">
     <ul id="p7menubar">
      <li><a href="Main.php?action=menu&click=home">Home</a></li>
      <li><a href="Main.php?action=menu&click=actions0">Actions</a></li>
      <li><a href="Main.php?action=menu&click=neighbors">Neighbors</a></li>
      <li><a href="Main.php?action=menu&click=fran">Franchises</a></li>
     </ul>
     <br class="clearit">
        <script language="javascript">
        P7_ExpMenu()
        </script>
     </div>';

if($server['click'] == "" || $server['click'] == "home")
 {
    echo '<br>';
    echo '<br>';
    echo 'Welcome to the plugin Neighbors<br>';
    echo '<hr>';
    //echo '<img border="0" hspace="0" src="http://images.piccsy.com/cache/images/meditation-dog-is-wise-90674-400-465.jpg" width="220" height="265" />';
    echo '
          <b>Actions</b> - Possible interations between you and your neighbors.
          <br>
          <b>Neighbors</b> - Complete list of your neighbors;
          <br>
          <b>Francises</b> - Complete list of your franchises;
         ';
 }

if(substr($server['click'],0,8) == "actions1") //saving data
{
/*  $tmp = substr($server['click'],8);
  $tmp = urldecode($tmp);
  //echo $tmp;
  $tmp1 = array();
  $tmp1 = json_decode($tmp);
  //var_dump($tmp1);*/
  echo '<br>Actions - Saved settings.<br><hr>';
  //$this->ld->SavePlSettings('neighborsplugin', $tmp1);
}
if(substr($server['click'],0,8) == "actions0")
{
 $mw = 'width="400"';
 $lw = 'width="150"';
echo  '<br>
       <table border="0" cellspacing="1" cellpadding="1" width="100%" bgcolor="#ff0066">
        <tr height="23">
         <td><h3>Neighbors &#187; You</h3></td>
        </tr>
       </table>

       <div style="margin-left: 20px">
       <input id="AcceptN" type="checkbox" value="0" size="4">Accept work from neighbors.<br>
       <br>
       <b>General Options:</b><br>
       <input id="sbAccepting" type="checkbox" value="0" size="4">Active Streak Bonus<br>
       <br>
       </div>
       <table border="0" cellspacing="1" cellpadding="1" width="100%" bgcolor="#ff0066">
        <tr height="23">
         <td><h3>Neighbors List</h3></td>
        </tr>
       </table>
       <div style="margin-left: 20px">
       <input id="all" type="radio"  class="check" name="dwork" checked value="alln">&nbsp;All
       <input class="check" id="all" type="radio" name="dwork" value="selected">&nbsp;Selected<br>
       <select style="width: 300px;" size="12" multiple name="nlist" id="nsp">' . $neighbours . ' </select>
       </div>
       <br>
       <table border="0" cellspacing="1" cellpadding="1" width="100%" bgcolor="#ff0066">
        <tr height="23">
         <td><h3>You &#187; Neighbors</h3></td>
        </tr>
       </table>
       <div style="margin-left: 20px">
       <table id="maint" border="0">
        <tr id="up">
         <td valign="top"> </td>
         <td valign="top" id="tdright" align="left"><div id="rcontent" align="left"></div></td>
        </tr>
        <tr id="down">
          <td colspan="2">
            <table>You have &nbsp;<span id="ncount"></span>&nbsp; neighbors, you can do &nbsp;<span id="act_count"></span>&nbsp; actions, please set how much actions should be done for every type, you can also set which item should be used for every action type.
              <tr>
               <td colspan="3">
                 <hr>
                 <b>General Options:</b><br>
                 <input id="heartP" type="checkbox" value="0" size="4">Do hearts in priority<br>
                 <input id="sbVisiting" type="checkbox" value="0" size="4">Active Streak Bonus
                 <hr>
               </td>
              </tr>
              <tr BGCOLOR="grey">
                <td><b>Construction Site</b></td>
                <td '.$mw.'>If selected this will be done first.</td>
                <td '.$lw.'>Reward</td>
              </tr>
              <tr>
                <td>Help Construction Site</td>
                <td '.$mw.'><input id="constr" type="text" value="0" size="4">&nbsp;&nbsp;&nbsp;item:&nbsp;<select id="constrIN" type="combo">'.$this->GetOptionsByClassName("ConstructionSite").'</select></td>
                <td '.$lw.'>Reputation & Coins</td>
              </tr>
              <tr BGCOLOR="grey">
                <td><b>Crops</b></td>
                <td '.$mw.'>If selected this will be done 2nd.</td>
                <td '.$lw.'>Reward</td>
              </tr>
              <tr>
                <td>Harvest crops</td>
                <td '.$mw.'><input id="cropsH" type="text" value="0" size="4">&nbsp;&nbsp;&nbsp;item:&nbsp;<select id="cropsHIN" type="combo">'.$this->GetOptionsByTypeName("plot_contract").'</select></td>
                <td '.$lw.'>Reputation & Goods</td>
              </tr>
              <tr>
                <td>Water crops</td>
                <td '.$mw.'><input id="cropsW" type="text" value="0" size="4">&nbsp;&nbsp;&nbsp;item:&nbsp;<select id="cropsWIN" type="combo">'.$this->GetOptionsByTypeName("plot_contract").'</select></td>
                <td '.$lw.'>Reputation & Goods</td>
              </tr>
              <tr>
                <td>Revive crops </td>
                <td '.$mw.'><input id="cropsR" type="text" value="0" size="4">&nbsp;&nbsp;&nbsp;item:&nbsp;<select id="cropsRIN" type="combo">'.$this->GetOptionsByTypeName("plot_contract").'</select></td>
                <td '.$lw.'>Reputation & Goods</td>
              </tr>
              <tr BGCOLOR="grey">
                <td><b>Ships</b></td>
                <td '.$mw.'>If selected this will be done 3rd.</td>
                <td '.$lw.'>Reward</td>
              </tr>
              <tr>
                <td>Harvest ships</td>
                <td '.$mw.'><input id="shipsH" type="text" value="0" size="4">&nbsp;&nbsp;&nbsp;item:&nbsp;<select id="shipsHIN" type="combo">'.$this->GetOptionsByTypeName("ship").'</select></td>
                <td '.$lw.'>Reputation & Goods</td>
              </tr>
              <tr>
                <td>Water ships</td>
                <td '.$mw.'><input id="shipsW" type="text" value="0" size="4">&nbsp;&nbsp;&nbsp;item:&nbsp;<select id="shipsWIN" type="combo">'.$this->GetOptionsByTypeName("ship").'</select></td>
                <td '.$lw.'>Reputation & Coins</td>
              </tr>
              <tr>
                <td>Revive ships </td>
                <td '.$mw.'><input id="shipsR" type="text" value="0" size="4">&nbsp;&nbsp;&nbsp;item:&nbsp;<select id="shipsRIN" type="combo">'.$this->GetOptionsByTypeName("ship").'</select></td>
                <td '.$lw.'>Reputation & Coins</td>
              </tr>
			  
			  
			  <tr BGCOLOR="grey">
                <td><b>Airline</b></td>
                <td '.$mw.'>&nbsp</td>
                <td '.$lw.'>Reward</td>
              </tr>
              <tr>
                <td>Harvest</td>
                <td '.$mw.'><input id="airH" type="text" value="0" size="4">&nbsp;&nbsp;&nbsp;item:&nbsp;<select id="airHIN" type="combo">'.$this->GetOptionsByTypeName("airplane").'</select></td>
                <td '.$lw.'>Reputation & Goods</td>
              </tr>
              <tr>
                <td>Accelerate</td>
                <td '.$mw.'><input id="airW" type="text" value="0" size="4">&nbsp;&nbsp;&nbsp;item:&nbsp;<select id="airWIN" type="combo">'.$this->GetOptionsByTypeName("airplane").'</select></td>
                <td '.$lw.'>Reputation & Coins</td>
              </tr>
              <tr>
                <td>Revive</td>
                <td '.$mw.'><input id="airR" type="text" value="0" size="4">&nbsp;&nbsp;&nbsp;item:&nbsp;<select id="airRIN" type="combo">'.$this->GetOptionByTypeAndKeyword("airplane", "cargoPlane").'</select></td>
                <td '.$lw.'>Reputation & Coins</td>
              </tr>

			 
			  
              <tr BGCOLOR="grey">
                <td><b>Visits</b></td>
                <td '.$mw.'>&nbsp</td>
                <td '.$lw.'>Reward</td>
              </tr>
              <tr>
                <td>Residences</td>
                <td '.$mw.'><input id="residence" type="text" value="0" size="4">&nbsp;&nbsp;&nbsp;item:&nbsp;<select id="residenceIN" type="combo">'.$this->GetOptionsByTypeName("residence").'</select></td>
                <td '.$lw.'>Reputation & Coins</td>
              </tr>
              <tr>
                <td>Landmarks</td>
                <td '.$mw.'><input id="landmark" type="text" value="0" size="4">&nbsp;&nbsp;&nbsp;item:&nbsp;<select id="landmarkIN" type="combo">'.$this->GetOptionsByTypeName("landmark").'</select></td>
                <td '.$lw.'>Reputation & Coins</td>
              </tr>
              <tr>
                <td>Community Buildings</td>
                <td '.$mw.'><input id="municipal" type="text" value="0" size="4">&nbsp;&nbsp;&nbsp;item:&nbsp;<select id="municipalIN" type="combo">'.$this->GetOptionsByTypeName("municipal").'</select></td>
                <td '.$lw.'>Reputation & Coins</td>
              </tr>

              <tr BGCOLOR="grey">
                <td><b>Visits Businesses</b></td>
                <td '.$mw.'>&nbsp</td>
                <td '.$lw.'>Reward</td>
              </tr>
              <tr>
                <td>Send bus to Mall1</td>
                <td '.$mw.'><input id="mall" type="text" value="0" size="4">&nbsp;&nbsp;&nbsp;item:&nbsp;<select id="mallIN" type="combo">'.$this->GetOptionsByTypeName("mall").'</select></td>
                <td '.$lw.'>Reputation & Coins</td>
              </tr>
              <tr>
                <td>Send bus to Mall2</td>
                <td '.$mw.'><input id="mall2" type="text" value="0" size="4">&nbsp;&nbsp;&nbsp;item:&nbsp;<select id="mall2IN" type="combo">'.$this->GetOptionsByTypeName("mall2").'</select></td>
                <td '.$lw.'>Reputation & Coins</td>
              </tr>
              <tr>
                <td>Send bus to Attractions</td>
                <td '.$mw.'><input id="attraction" type="text" value="0" size="4">&nbsp;&nbsp;&nbsp;item:&nbsp;<select id="attractionIN" type="combo">'.$this->GetOptionsByTypeName("attraction").'</select></td>
                <td '.$lw.'>Reputation & Coins</td>
              </tr>
              <tr>
                <td>Send bus to Business</td>
                <td '.$mw.'><input id="business" type="text" value="0" size="4">&nbsp;&nbsp;&nbsp;item:&nbsp;<select id="businessIN" type="combo">'.$this->GetOptionsByTypeName("business").'</select></td>
                <td '.$lw.'>Reputation & Coins</td>
              </tr>

              <tr BGCOLOR="grey">
                <td><b>Clear wilderness.</b></td>
                <td '.$mw.'>&nbsp</td>
                <td '.$lw.'>Reward</td>
              </tr>
              <tr>
                <td>Chop trees</td>
                <td '.$mw.'><input id="trees" type="text" value="0" size="4">&nbsp;&nbsp;&nbsp;item:&nbsp;<select id="treesIN" type="combo">'.$this->GetOptionsByTypeName("wilderness").'</select></td>
                <td '.$lw.'>Reputation & Coins</td>
              </tr>

              <tr BGCOLOR="grey">
                <td><b>Max neighbors/cycle</b></td>
                <td '.$mw.'>&nbsp</td>
              </tr>
              <tr>
                <td>Amount of N per cycle</td>
                <td><input id="Pcycle" type="text" value="1000" size="4">&nbsp; 0 = all</td>
              </tr>

              <tr BGCOLOR="silver">
                <td><b>Build a Franchise</b></td>
                <td '.$mw.'> This will cost you coins/cash.</td>
              </tr>
              <tr>
                <td>Build franchise </td>
                <td '.$mw.'><input id="franchise" type="text" value="0" size="4">&nbsp;&nbsp;&nbsp;item:&nbsp;<select id="franchiseIN" type="combo">'.$this->GetALLFranchise().'</select></td>
              </tr>
              <tr BGCOLOR="silver">
                <td><b>Accept a Franchise</b></td>
                <td '.$mw.'></td>
              </tr>
              <tr>
                <td>Requests </td>
                <td '.$mw.'>Select from the list:<br><select style="width: 300px;" size="6" multiple name="flist" id="asp">' . $fRequests . ' </select></td>
              </tr>
            </table>
            <br>
            <br>
            <hr>
            <input id="pause" type="checkbox" checked value="0" size="4">Pause!<br>
            &nbsp;* When this is checked you will not visit your neighbors;<br>
            &nbsp;* Uncheck and save, if you wanna visit the selected neighbors on the next run;
          </td>
        </tr>
       </table>
       </div>
       <div width="100%" align="center"><br>
       <hr>
       <button id="btn_save" style="color:white;background-color:#13a89e;border-width:1px;border-style:solid;">&nbsp; Save Settings&nbsp;</button>
       </div>
       <hr>';
}
if($server['click'] == "neighbors")
{
echo '<div style="margin-left: 20px">
     <br>
     <h2>Complete list of Neighbors:</h2>
     <table border="1">
     <tr style="font-weight: bold;">
        <td>&nbsp;</td>
        <td>uid</td>
        <td>Name</td>
        <td>City Name</td>
        <td>Coins</td>
        <td>XP</td>
        <td>Level</td>
      </tr>';
      $res=$this->ld->GetSelect("select * from neighborlist order by level");
      foreach ($res as $val)
      {
        //0[uid] NVARCHAR(25) NULL,
        //1[name] NVARCHAR(50) NULL,
        //2[picture] NVARCHAR(50) NULL,
        //3[cityname] NVARCHAR(50) NULL,
        //4[xp] NVARCHAR(10) NULL,
        //5[coins] NVARCHAR(20) NULL,
        //6[level] NVARCHAR(5)  NULL)

        echo '<tr>';
        echo '<td><img border="0" hspace="0" src="'.(string)$val[2].'" width="28" height="30" /></td>'; //picture
        echo '<td>'.(string)$val[0].'</td>'; //uid
        echo '<td>'.(string)$val[1].'</td>'; //name
        echo '<td>'.(string)$val[3].'</td>'; //cityname
        echo '<td>'.(string)$val[5].'</td>'; //coins
        echo '<td>'.(string)$val[4].'</td>'; //xp
        echo '<td>'.(string)$val[6].'</td>'; //level
        echo '</tr>';
      }
echo '</table >
      <br>
      <hr>';
}
if($server['click'] == "fran")
{
echo '<div style="margin-left: 20px">
     <br>
     <h2>Franchises that you can place:</h2>
     <table border="1">
     <tr>
        <td>Type:</td>
        <td>Franchise name:</td>
        <td>How many you have:</td>
      </tr>';
      $res=$this->ld->GetSelect("select * from franchises");
      foreach ($res as $val)
      {
        $v=(string)$val[1];
        $obj=unserialize(base64_decode($v));
        $name =$obj['name'];
        $franchise_name      = $obj['franchise_name'];//  Kara's Bike Shop
        $time_last_collected = $obj['time_last_collected'];//  time_last_collected  Number  1293056411
        echo '<tr>';
        echo '<td>'.$name.'</td>';
        echo '<td>'.$franchise_name.'&nbsp;</td>';
        if(isset($obj['locations'])) { $howm = count($obj['locations']); }else{ $howm = 0;}
        echo '<td>'. $howm.'</td>';
        echo '</tr>';
      }
echo '</table >
      <br>
      <hr>

      <h2>Neighbors that have open space for your business</h2>
      <hr>
      <br>
      This list is filled after you have visited your neighbors. It will stay for 24 hours in the list, before to be deleted from the list.
      </div>
      <div style="margin-left: 20px">
      <table id="maint" border="0">
       <tr id="up">
         <td width="350" height="200" valign="top"><span id="lotsite"></span></td>
       </tr>
      </table>
      </div>';
}

    echo '</body></html>';
    }
}

?>